// const host = "https://yuleren.cn/api/";
const host =  "https://yulemen.fun/api/"
// console.log(getApp().globalData.token, 'token')
let token = '';

function reqeust(url, params) {

  if (!token) {
    token = wx.getStorageSync('token');
  }
  return new Promise((resolve, reject) => {
    console.log('参数', params)
    wx.uploadFile({
      url: host + url, // 目标服务器url
      filePath: params,
      header: {
        'Authorization': token ? `${token}` : '',
      },
      name: 'file',
      success: (res) => {
        let data = JSON.parse(res.data)
        console.log(data);
        if (data.code === 200) {
          resolve(data.data)
        } else {
          wx.showToast({
            title: `接口异常，原因如下：${data.message}`,
            icon: 'none'
          });
          reject(data)
        }
      },
      fail: (res) => {
        wx.showToast({
          title: '网络错误...',
          icon: 'loading'
        });
        reject(res)
      }
    });
  })
}

export default {
  reqeust
}